/*
 * wav.h
 *
 *  Created on: Apr 27, 2011
 *      Author: tommy
 */

#ifndef WAV_H_
#define WAV_H_

typedef unsigned int	DWORD;
typedef unsigned short int 	WORD;
typedef unsigned char	BYTE;
typedef DWORD FOURCC;  //Four-character code
typedef FOURCC CKID;   //Four-character-code chunk identifier
typedef DWORD CKSIZE;  //32-bit unsigned size value

typedef struct{
	CKID 	chunkID;
	CKSIZE 	chunkSize;
	CKID	format;
}RIFF_CK;

typedef struct{
    CKID	chunkID;    //'fmt '
    CKSIZE	chunkSize; // 16 para PCM.Size of rest of subchunk.
    /* Common fields */
    WORD	wFormatTag; // Format category,i.e.:PCM = 1 (no compres.)
    WORD	wChannels; // Number of channels:1, mono; 2, stereo
    DWORD	dwSamplesPerSec;     // Sampling rate: Mhz
    DWORD	dwAvgBytesPerSec;
    WORD	wBlockAlign;
    WORD	wBitsPerSample; //8, 16, etc.
    //WORD	extraParamSize;// If PCM, doesn't exist
    //BYTE	*extraParams;//space for extra params
}FMT_CK;

typedef struct{
    CKID	chunkID;    // 'data'
    CKSIZE	chunkSize; // Bytes of data
    BYTE	*soundData; // Sound data.
}DATA_CK;

typedef struct
{
    RIFF_CK	riff_desc; // MANDATORY
    FMT_CK	fmt;         // Format Chunk MANDATORY
    //FACT_CK fact;     // Fact Chunk OPTIONAL
    //CUE_CK cue;       // Cue points Chunk OPTIONAL
    //PLIST_CK    plist;// Playlist Chunk OPTIONAL
    //LIST_CK list;     // Associated data list Chunk OPTIONAL
    // more optional data...
    DATA_CK	data;       // Wave Data Chunk MANDATORY
} wavT;

wavT * loadWavFile(char * wavfile);
int saveWavFile(char * wavfile, wavT * wav);

#endif /* WAV_H_ */
